<?php 
## include required files
/*******************************/
require_once '../model/budget.php';
/*******************************/
## Create Objects
/*******************************/
$budgetObj = new Model_Budget();
/*******************************/

if(isset($_POST['editbudget_btn']) || $_POST['budgetname']) {
	
	## apply PHP validation for required filed
	if( $_POST['budgetname'] != '') 
	{	
		if($_POST['budgetfrom'] < $_POST['budgetto'])
		{
			extract($_POST);
			$budgeteditArray['budget_name']   = return_post_value($_POST['budgetname']);		
			$budgeteditArray['budgetfrom']   		  = $_POST['budgetfrom'];		
			$budgeteditArray['budgetto']   		  = $_POST['budgetto'];		
			$budgetObj->editBudgetById($budgeteditArray,$_POST['budgetId']);
			
			$_SESSION['msg'] = "<div class='success_msg'><span>Budget edited successfully</span></div>";
			header('location:'.SITE_URL.'/admin/home.php?q=budget&page='.$_GET['page']);
			exit;
		}
		else
			$_SESSION['msg'] = '<div class="error_msg"><span>Please enter budget range to greater than budget range from</span></div>';
				
	} else {// php validation else
		$_SESSION['msg'] = '<div class="error_msg"><span>Please fill all required fields</span></div>';
	}
	// main if closed
}




if($_GET['id'] != ''&& $_GET['action'] == 'edit') {
	$budget_id = base64_decode($_GET['id']);
	$budgetDetArray = $budgetObj->getBudgetDetailsById($budget_id);	
	$smarty->assign('budgetDetArray', $budgetDetArray);
}

## Assign success or error msg to smarty variable and unset session variable
if(trim($_SESSION['msg']) != '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}

## Set active class variable for left menu
$smarty->assign('activeclass', 'budget');
$smarty->assign('mainmenu', '2');
## Unset all the objects created which are on this page

unset($budgetObj);



$smarty->display(TEMPLATEDIR_ADMIN. 'budget/editbudget.tpl');
unset($smarty);
?>